#import "OrderLogic.h"
#import "OrderModel.h"
@implementation OrderLogic
- (instancetype)init
{
    self = [super init];
    if (self) {
        _page = 1;
        _dataArray = [NSMutableArray array];
    }
    return self;
}
-(void)loadData
{
    if (_page == 1) {
        [_dataArray removeAllObjects];
    }
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"rank_api" A:@"charm_rank_list"];
    if([self.type isEqualToString:@"1"])
    {
    }
    else if([self.type isEqualToString:@"2"])
    {
        url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"rank_api" A:@"wealth_rank_list"];
    }
    else if([self.type isEqualToString:@"3"])
    {
        url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"page_data_api" A:@"get_news_user_list"];
    }
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:@(_page) forKey:@"page"];
    [param setObject:self.subClass forKey:@"type"];
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
    } success:^(id responseObject) {
        if (_page == 1) {
            [_dataArray removeAllObjects];
        }
        _myRankings = [NSString stringWithFormat:ASLocalizedString(@"我的排名:%@"),[responseObject valueForKey:@"order_num"]];
        NSArray *tmpArr = [NSMutableArray modelArrayWithClass:[OrderModel class] json:[responseObject valueForKey:@"list"]];
        NSMutableArray *list = [NSMutableArray arrayWithArray:tmpArr];
        if(_page == 1 && ![self.type isEqualToString:@"3"])
        {
            if(list.count !=0)
            {
                _firstUser = [list firstObject];
                [list removeObjectAtIndex:0];
            }
            else
            {
                _firstUser = [[OrderModel alloc] init];
            }
        }
        else if(_page == 1 && [self.type isEqualToString:@"3"])
        {
            NSArray *tmpArr = [NSMutableArray modelArrayWithClass:[OrderModel class] json:[responseObject valueForKey:@"data"]];
            list = [NSMutableArray arrayWithArray:tmpArr];
        }
        [_dataArray addObjectsFromArray:list];
        if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestDataCompleted)]) {
            [self.delegagte requestDataCompleted];
        }
    } failure:^(NSString *error) {
    } hasCache:YES];
}
@end
